import Router from 'koa-router'
import { Models } from '@/common/typings/modle'
import Config from '@/config/Config'
import { Success } from '@/core/HttpException'
import { command } from '@/server/mysql'
import { getFields, getFieldValues } from '@/common/utils/sql'
import { format } from '@/common/utils/date'
import verifyToken from '@/middlewares/verifyToken'

const router = new Router({
  prefix: `${Config.API_PREFIX}v1/system/common/log`,
})

/*
 * 上传图片
 */
router.post('/save', verifyToken, async (ctx: Models.Ctx) => {
  const { type, familyId, content } = ctx.request.body as any
  const fieldObj = {
    type,
    familyId,
    content,
    operator: ctx.auth.userName,
    createTime: format(new Date()),
  }
  const result = (await command(`INSERT INTO system_log (${getFields(fieldObj)}) VALUES (${getFieldValues(fieldObj)})`))
    .results
  console.log('result:', result)
})

export default router
